﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YiNing.Tools;
using YiNing.UI.Forms;

namespace LixunYueNan
{
    public class LixunArgs
    {
        /// <summary>
        /// mes网址
        /// </summary>
        [Category("基础参数")]
        [DisplayName("Mes网址")]
        [Description("mes请求的网址")]
        public string BaseMesUrl { get; set; }
        [Category("基础参数")]
        [DisplayName("工位站点[tsid]")]
        [Description("轨道的站点[tsid]")]
        public string BaseTsid { get; set; }

        [Category("基础参数")]
        [DisplayName("测试机台站点[test_station_name]")]
        [Description("轨道测试机台站点[test_station_name]")]
        //[Browsable(false)]
        public string BaseTestStationName { get; set; }

        [Category("基础参数")]
        [DisplayName("程式版本[sw_version]")]
        [Description("程式版本，如无可为空[sw_version]")]
        //[Browsable(false)]
        public string BaseSwVersion { get; set; }

        [Category("基础参数")]
        [DisplayName("治具编号[fixture_id]")]
        [Description("测试机治具编号，可配置[fixture_id]")]
        //[Browsable(false)]
        public string BaseFixtureId { get; set; }

        [Category("基础参数")]
        [DisplayName("工号[op]")]
        [Description("工号[op]")]
        //[Browsable(false)]
        public string BaseOP { get; set; }

        #region 查询接口参数
        [Category("查询")]
        [DisplayName("P")]
        [Description("P")]
        public string CheckRouteP { get; set; }

        [Category("查询")]
        [DisplayName("C")]
        [Description("C")]
        public string CheckRouteC { get; set; }

        //[Category("查询")]
        //[DisplayName("TARY盘码")]
        //[Description("TARY盘码")]
        ////[Browsable(false)]
        //public string CheckRouteSN { get; set; }

        //[Category("查询")]
        //[DisplayName("治具码")]
        //[Description("治具码，变量，测试扫描，如无可为空")]
        ////[Browsable(false)]
        //public string CheckRouteFixtureId { get; set; }

        //[Category("查询")]
        //[DisplayName("穴位码")]
        //[Description("穴位码，变量，测试扫描，如无可为空")]
        ////[Browsable(false)]
        //public string CheckRouteHeadId { get; set; }

        [Category("查询")]
        [DisplayName("模式检查[audit_mode]")]
        [Description("audit_mode:测试模式  0:代表正常模式   1:代表复测模式\nDLCXXX 需使用: 复测模式 / 当前:正常模式--------使用模式错误\nDLCXXX 需使用: 正常模式 / 当前:复测模式--------使用模式错误\nDLCXXX当前模式不存在-------- - 模式上传错误或为空")]
        //[Browsable(false)]
        public string CheckRouteAuditMode { get; set; }
        #endregion


        #region 过站
        [Category("过站")]
        [DisplayName("过站C")]
        [Description("C")]
        //[Browsable(false)]
        public string ThroughRouteC { get; set; }

        [Category("过站")]
        [DisplayName("过站P")]
        [Description("P")]
        //[Browsable(false)]
        public string ThroughRouteP { get; set; }

        [Category("过站")]
        [DisplayName("机种")]
        [Description("机种[product]")]
        //[Browsable(false)]
        public string ThroughRouteProduct { get; set; }
        #endregion

        #region 解绑
        [Category("解绑")]
        [DisplayName("启用解绑")]
        [Description("是否启用解绑")]
        [ReadOnly(true)]
        public bool UnbindEnable { get; set; }
        [Category("解绑")]
        [DisplayName("C")]
        [Description("C")]
        //[Browsable(false)]
        public string UnbindC { get; set; }

        [Category("解绑")]
        [DisplayName("P")]
        [Description("P")]
        //[Browsable(false)]
        public string UnbindP { get; set; }
        #endregion
        /// <summary>
        /// 保存自己
        /// </summary>
        public void SaveThis()
        {
            JsonHelper.Serialize(this, GetThisFileName());
        }

        /// <summary>
        /// 加载配置
        /// </summary>
        /// <returns></returns>
        public static LixunArgs LoadThis(int line = 1)
        {
            var res = JsonHelper.DeserializeByFile<LixunArgs>(GetThisFileName(line));
            if (res == null)
            {
                DarkMessageBox.ShowWarning("加载配置文件异常,参数初始化");
                res = new LixunArgs();
            }
            return res;
        }
        /// <summary>
        /// 获取本身的文件名
        /// </summary>
        /// <returns></returns>
        public static string GetThisFileName(int line = 1)
        {
            string name = line == 1 ? "Plugins/LixunYueNan/config1.zyn" : "Plugins/LixunYueNan/config2.zyn";
            return Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, name);
        }


    }
}
